package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.Flow;
import com.ysqcould.allocation.domain.WxRole;
import com.ysqcould.allocation.service.IFlowService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/allocation/flow")
public class FlowController extends BaseController
{
    @Autowired
    private IFlowService flowService;

    /**
     * 查询流程列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:flow:list')")
    @GetMapping("/list")
    public TableDataInfo list(Flow flow)
    {
        startPage();
        List<Flow> list = flowService.selectFlowList(flow);
        return getDataTable(list);
    }

    /**
     * 导出流程列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:flow:export')")
    @Log(title = "流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Flow flow)
    {
        List<Flow> list = flowService.selectFlowList(flow);
        ExcelUtil<Flow> util = new ExcelUtil<Flow>(Flow.class);
        util.exportExcel(response, list, "流程数据");
    }

    /**
     * 获取流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:flow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(flowService.selectFlowById(id));
    }

    /**
     * 新增流程
     */
    @PreAuthorize("@ss.hasPermi('allocation:flow:add')")
    @Log(title = "流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Flow flow)
    {
        flow.setAsId(getUserId());
        return toAjax(flowService.insertFlow(flow));
    }

    /**
     * 修改流程
     */
    @PreAuthorize("@ss.hasPermi('allocation:flow:edit')")
    @Log(title = "流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Flow flow)
    {
        return toAjax(flowService.updateFlow(flow));
    }

    /**
     * 删除流程
     */
    @PreAuthorize("@ss.hasPermi('allocation:flow:remove')")
    @Log(title = "流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(flowService.deleteFlowByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Flow flow)
    {
        return toAjax(flowService.updateStatus(flow));
    }
}
